//
//  UIImage+Extension.swift
//  照片设置
//
//  Created by Dengdwd on 15/10/20.
//  Copyright © 2015年 dwd. All rights reserved.
//

import UIKit

extension UIImage {
    
    func imageWithScaleWidth(width:CGFloat)->UIImage{

        
        if self.size.width < width {
        return self
        }
        
        let height = width * self.size.height / self.size.width
        
        UIGraphicsBeginImageContext(CGSize(width: width, height: height))
        
        drawInRect(CGRect(x: 0, y: 0, width: width, height: height))
        
        let image = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return image
    }
    
    
}
